/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI;

import BUS.CTPhieuDatPhong_BUS;
import BUS.PhieuDatPhong_BUS;
import BUS.Phong_BUS;
import DTO.PhieuDatPhong_DTO;
import DTO.Phong_DTO;
import GUI.Menu.JIFBaoCao;
import GUI.Menu.JIFQLDatTiec;
import GUI.Menu.JIFDichVu;
import GUI.Menu.JIFQLThuePhong;
import GUI.Menu.JIFThongTin;
import GUI.Menu.JIFTimKiem;
import java.awt.Toolkit;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JComponent;
import javax.swing.JInternalFrame;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.plaf.DesktopPaneUI;

/**
 *
 * @author Mr
 */
public class MainFrame extends javax.swing.JFrame {

    /**
     * Creates new form MainFrame
     */
    public MainFrame() {
        initComponents();
        huyPhieuDatQuaHan();
        this.setLocation(100, 10);
        this.setIconImage(Toolkit.getDefaultToolkit().getImage("src/Image/hotel.png"));
        imgView.setImage(Toolkit.getDefaultToolkit().getImage("src/Image/uit_logo_new.jpg"));
        // Set giao dien cac ChildFrom
        desktopChucNang.setUI(new DesktopPaneUI() {
            @Override
            public void installUI(JComponent c) {
                // TODO Auto-generated method stub
                try {
                    UIManager.setLookAndFeel("com.jtattoo.plaf.texture.TextureLookAndFeel");
                    //UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
                } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) {
                }
                super.installUI(c);
            }
        });
        JIFQLThuePhong frameThue;
        try {
            frameThue = new JIFQLThuePhong();
            setSize(frameThue);
            frameThue.setVisible(true);
            frameThue.setDesktop(desktopChucNang);
            desktopMenu.add(frameThue);
            frameThue.setSelected(true);
        } catch (Exception e) {
        }
    }
    // Set kich thuoc cac tab menu

    private void setSize(JInternalFrame frm) {
        frm.setSize(980, 90);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        btQuanLyDichVu = new javax.swing.JButton();
        btQLThuePhong = new javax.swing.JButton();
        btTimKiem = new javax.swing.JButton();
        btQuanLyDatTiec = new javax.swing.JButton();
        btBaoCao = new javax.swing.JButton();
        btThongTin = new javax.swing.JButton();
        desktopMenu = new javax.swing.JDesktopPane();
        desktopChucNang = new javax.swing.JDesktopPane();
        jPanel2 = new javax.swing.JPanel();
        imgView = new org.jdesktop.swingx.JXImageView();
        btThoat = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("CHƯƠNG TRÌNH QUẢN LÝ KHÁCH SẠN PARADISE");
        setBackground(new java.awt.Color(0, 102, 153));
        setResizable(false);

        jPanel1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(204, 0, 51), 3));

        btQuanLyDichVu.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/DichVu.png"))); // NOI18N
        btQuanLyDichVu.setText("Quản lý dịch vụ");
        btQuanLyDichVu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btQuanLyDichVuActionPerformed(evt);
            }
        });

        btQLThuePhong.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/Thue.png"))); // NOI18N
        btQLThuePhong.setText("Quản lý thuê phòng");
        btQLThuePhong.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btQLThuePhongActionPerformed(evt);
            }
        });

        btTimKiem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/search.png"))); // NOI18N
        btTimKiem.setText("Tìm Kiếm");
        btTimKiem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btTimKiemActionPerformed(evt);
            }
        });

        btQuanLyDatTiec.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/party.png"))); // NOI18N
        btQuanLyDatTiec.setText("Quản lý đặt tiệc");
        btQuanLyDatTiec.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btQuanLyDatTiecActionPerformed(evt);
            }
        });

        btBaoCao.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/document.png"))); // NOI18N
        btBaoCao.setText("Hóa Đơn và Báo Cáo");
        btBaoCao.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btBaoCaoActionPerformed(evt);
            }
        });

        btThongTin.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/About-icon.png"))); // NOI18N
        btThongTin.setText("Thông Tin");
        btThongTin.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btThongTinActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btQuanLyDichVu, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btTimKiem, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btQLThuePhong, javax.swing.GroupLayout.DEFAULT_SIZE, 170, Short.MAX_VALUE)
                    .addComponent(btQuanLyDatTiec, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btBaoCao, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btThongTin, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(btQLThuePhong, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btQuanLyDichVu, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btQuanLyDatTiec, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btTimKiem, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btBaoCao, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btThongTin, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        desktopMenu.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(204, 0, 0), 2));

        desktopChucNang.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(204, 0, 0), 2));

        imgView.setEditable(false);

        javax.swing.GroupLayout imgViewLayout = new javax.swing.GroupLayout(imgView);
        imgView.setLayout(imgViewLayout);
        imgViewLayout.setHorizontalGroup(
            imgViewLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );
        imgViewLayout.setVerticalGroup(
            imgViewLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 89, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(imgView, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(imgView, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(0, 0, 0))
        );

        btThoat.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/close.png"))); // NOI18N
        btThoat.setText("Thoát");
        btThoat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btThoatActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(desktopMenu, javax.swing.GroupLayout.PREFERRED_SIZE, 980, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(17, 17, 17)
                                .addComponent(btThoat, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(desktopChucNang)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(desktopMenu)
                    .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(desktopChucNang, javax.swing.GroupLayout.DEFAULT_SIZE, 561, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(59, 59, 59)
                        .addComponent(btThoat, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btQLThuePhongActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btQLThuePhongActionPerformed
        // TODO add your handling code here:
        if (desktopChucNang.getComponentCount() != 0) {
            desktopChucNang.getComponent(0).setVisible(false);
        }
        desktopChucNang.removeAll();
        JIFQLThuePhong frameThue;
        try {
            frameThue = new JIFQLThuePhong();
            setSize(frameThue);
            frameThue.setVisible(true);
            frameThue.setDesktop(desktopChucNang);
            desktopMenu.add(frameThue);
            frameThue.setSelected(true);
        } catch (Exception e) {
        }
    }//GEN-LAST:event_btQLThuePhongActionPerformed

    private void btQuanLyDichVuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btQuanLyDichVuActionPerformed
        // TODO add your handling code here:
        if (desktopChucNang.getComponentCount() != 0) {
            desktopChucNang.getComponent(0).setVisible(false);
        }
        desktopChucNang.removeAll();
        JIFDichVu frameDichVu;
        try {
            frameDichVu = new JIFDichVu();
            setSize(frameDichVu);
            frameDichVu.setVisible(true);
            frameDichVu.setDesktop(desktopChucNang);
            desktopMenu.add(frameDichVu);
            frameDichVu.setSelected(true);
        } catch (Exception e) {
        }
    }//GEN-LAST:event_btQuanLyDichVuActionPerformed

    private void btQuanLyDatTiecActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btQuanLyDatTiecActionPerformed
        // TODO add your handling code here:
        if (desktopChucNang.getComponentCount() != 0) {
            desktopChucNang.getComponent(0).setVisible(false);
        }
        desktopChucNang.removeAll();
        JIFQLDatTiec frame;
        try {
            frame = new JIFQLDatTiec();
            setSize(frame);
            frame.setVisible(true);
            frame.setDesktop(desktopChucNang);
            desktopMenu.add(frame);
            frame.setSelected(true);
        } catch (Exception e) {
        }
    }//GEN-LAST:event_btQuanLyDatTiecActionPerformed

    private void btTimKiemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btTimKiemActionPerformed
        // TODO add your handling code here:
        if (desktopChucNang.getComponentCount() != 0) {
            desktopChucNang.getComponent(0).setVisible(false);
        }
        desktopChucNang.removeAll();
        JIFTimKiem frame;
        try {
            frame = new JIFTimKiem();
            setSize(frame);
            frame.setVisible(true);
            frame.setDesktop(desktopChucNang);
            desktopMenu.add(frame);
            frame.setSelected(true);
        } catch (Exception e) {
        }
    }//GEN-LAST:event_btTimKiemActionPerformed

    private void btBaoCaoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btBaoCaoActionPerformed
        // TODO add your handling code here:
        if (desktopChucNang.getComponentCount() != 0) {
            desktopChucNang.getComponent(0).setVisible(false);
        }
        desktopChucNang.removeAll();
        JIFBaoCao frame;
        try {
            frame = new JIFBaoCao();
            setSize(frame);
            frame.setVisible(true);
            frame.setDesktop(desktopChucNang);
            desktopMenu.add(frame);
            frame.setSelected(true);
        } catch (Exception e) {
        }
    }//GEN-LAST:event_btBaoCaoActionPerformed

    private void btThoatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btThoatActionPerformed
        // TODO add your handling code here:
        this.dispose();
    }//GEN-LAST:event_btThoatActionPerformed

    private void btThongTinActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btThongTinActionPerformed
        // TODO add your handling code here:
        if (desktopChucNang.getComponentCount() != 0) {
            desktopChucNang.getComponent(0).setVisible(false);
        }
        desktopChucNang.removeAll();
        JIFThongTin frame;
        try {
            frame = new JIFThongTin();
            setSize(frame);
            frame.setVisible(true);
            frame.setDesktop(desktopChucNang);
            desktopMenu.add(frame);
            frame.setSelected(true);
        } catch (Exception e) {
        }
    }//GEN-LAST:event_btThongTinActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel("com.jtattoo.plaf.smart.SmartLookAndFeel");
                    //javax.swing.UIManager.setLookAndFeel("com.jtattoo.plaf.acryl.AcrylLookAndFeel");
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new MainFrame().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btBaoCao;
    private javax.swing.JButton btQLThuePhong;
    private javax.swing.JButton btQuanLyDatTiec;
    private javax.swing.JButton btQuanLyDichVu;
    private javax.swing.JButton btThoat;
    private javax.swing.JButton btThongTin;
    private javax.swing.JButton btTimKiem;
    private javax.swing.JDesktopPane desktopChucNang;
    private javax.swing.JDesktopPane desktopMenu;
    private org.jdesktop.swingx.JXImageView imgView;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    // End of variables declaration//GEN-END:variables
    public static void huyPhieuDatQuaHan() {
        SimpleDateFormat format = new SimpleDateFormat("MM-dd-yyyy");
        Date dtoday = new Date(System.currentTimeMillis() - 100742784);
        String today = format.format(dtoday);
        try {
            ArrayList<PhieuDatPhong_DTO> ds = PhieuDatPhong_BUS.layDSMaPhieuDatQuaHan(today);
            for (int i = 0; i < ds.size(); i++) {
                String maPhieuDat = ds.get(i).getMaPhieuDat().toString();
                ArrayList<Phong_DTO> dsmaPhong;
                dsmaPhong = PhieuDatPhong_BUS.layDSMaPhongDat(maPhieuDat);
                for (int j = 0; j < dsmaPhong.size(); j++) {
                    Phong_BUS.capnhattinhtrangDat(dsmaPhong.get(j).getMaPhong().toString(), "Trống");
                }
                CTPhieuDatPhong_BUS.Delete(maPhieuDat);
                PhieuDatPhong_BUS.Delete(maPhieuDat);
            }

        } catch (Exception ex) {
            Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
